<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>记账系统 - 首页</title>
<!--[if lt IE 9]>
  <script src="libs/html5shiv.min.js"></script>
  <script src="libs/respond.min.js"></script>
  <![endif]-->
<script src="libs/jquery-1.12.1.min.js"></script>
<link href="libs/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="libs/bootstrap-3.3.6/js/bootstrap.min.js"></script>
<script src="libs/js.cookie-2.1.0.min.js"></script>
<script src="libs/getQueryString.js"></script>
<script src="libs/handlebars.min.js"></script>

</head>
<body>
	<div class="container">
		<div class="row">
			<div class="col-md-2">
				<ul class="nav nav-pills">
					<li class="active">
						<button id="logout" class="btn btn-primary btn-block">退出当前用户</button>
					</li>
				</ul>
			</div>
		</div>
	</div>

	<div class="container">
		<div class="row">
			<div class="page-header">
				<h2>
					<strong>记账</strong>
				</h2>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-md-8">
				<ul class="nav nav-pills">
					<li><a href="#">用户： <span id="text3"></span>
					</a></li>

					<li class="active"><a href="#">首页</a></li>
					<li><a href="xjsr.html">新加收入</a></li>
					<li><a href="xjzc.html">新加支出</a></li>
					<li><a href="month.html">当月统计</a></li>
					<li><a href="queryall.html">查询</a></li>

				</ul>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<hr />
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="panel panel-success">
			<div class="panel-heading">一周内的收入</div>
			<div class="panel-body" id="text1"></div>
		</div>
	</div>

	<div class="col-md-6">
		<div class="panel panel-success">
			<div class="panel-heading">一周内的支出</div>
			<div class="panel-body" id="text2"></div>
		</div>
	</div>
	<div class="col-md-12">
		<div class="panel panel-primary">
			<div class="panel-heading">最近的四笔收入</div>
			<div class="panel-body" id="list1"></div>
		</div>
	</div>

	<div class="col-md-12">
		<div class="panel panel-primary">
			<div class="panel-heading">最近的四笔支出</div>
			<div class="panel-body" id="list2"></div>
		</div>
	</div>


	<script type="text/javascript">
		$(function() {
			$.getJSON('query_income.action', function(res) {
				console.log(res);
				$('#text1').text(res[0].sumin);
			});
			$.getJSON('query_pay.action', function(res) {
				console.log(res);
				$('#text2').text(res[0].sumout);

			});
			$.getJSON('query_nickname.action', function(res) {
				console.log(res);
				$('#text3').text(res.nickname);

			});
			$.getJSON('querysr.action', function(res) {
				console.log(res);
				var data = {
					'item' : res
				};
				var t = Handlebars.compile($('#template').html());
				$('#list1').html(t(data));

			});
			$.getJSON('queryzc.action', function(res) {
				console.log(res);
				//res存在 json里  再把res存在item（json）里面  
				var data = {
					'item' : res
				};
				//调用Handlebars里面compile的这个方法，把 template 显示出来
				var t = Handlebars.compile($('#template').html());
				//必须需要 这样的形式 ：[{"fm":"300"},{"fm":"400"}]  才能显示出来 
				$('#list2').html(t(data));
			});

			$('#logout').click(function() {
				$.post('logout.action', {}, function(res, status) {
					window.location.href = "login.html";
				});

			});

		});
	</script>

	<script id="template" type="text/x-handlebars-template">
	{{#each item}}
		<div class="panel panel-default col-md-3">
			<div class="panel-body">
				<dl>
					<dt>时间</dt><dd>{{date_time}}</dd>
					<dt>地点</dt><dd>{{place}}</dd>
					<dt>金额</dt><dd>{{m}}</dd>
					<dt>类别</dt><dd>{{kind}}</dd>
				</dl>
			</div>
		</div>
	{{/each}}

	</script>
	<script type="text/javascript">
		if (!Cookies.get("result")) {
			window.locaion.href = 'login.html';
		}
		if (Cookie.get('result') == '') {
			window.locaion.href = 'login.html';
		}
	</script>



</body>
</html>